<script setup lang="ts">
// hooks
import { Cell, CellGroup, Toast, Button } from 'vant';
import { get, request } from 'rbtsdk/request';
import { getQueryStr } from 'rbtsdk/utils';
import { onBeforeMount, toRefs } from 'vue';
import { useUserStore } from '@/stores/user';

onBeforeMount(async () => {
  const res = await get('https://jsonplaceholder.typicode.com/todos/1', {
    params: {
      columnId: 29933922,
    },
  });
  if (res.success) {
    // ....
  } else {
    Toast(res.info);
  }
  console.log('res', res);
  // 错误请求;
  const res2 = await request({
    url: '//notfound404',
  });
  console.log('res2', res2);
  // 获取参数
  console.log('getQueryStr', getQueryStr(''));
});

const user = useUserStore();

const { name, isLogin } = toRefs(user);

const loginHandle = () => {
  user.login('user' + Math.random());
};

const logoutHandle = () => {
  user.loginOut();
};
</script>

<template>
  <CellGroup>
    <Cell title="About" is-link to="/about"></Cell>
    <Cell title="Swiper" is-link to="/swiper"></Cell>
  </CellGroup>
  <br />
  <p>
    <Button v-if="!isLogin" @click="loginHandle">登录</Button>
    <Button v-if="isLogin" @click="logoutHandle">注销</Button>
  </p>
  <p v-if="isLogin">{{ name }}</p>
</template>
